<?
require "include/bittorrent.php";
dbconn();
loggedinorreturn();

if (get_user_class() < UC_ADMINISTRATOR)
	error("Permission denied");

stdhead("Duplicate Accounts");
print("<h1>Duplicate Accounts:</h1>\n");

$res = query("SELECT COUNT(id) AS counting, identhash FROM users WHERE identhash <> '' GROUP BY identhash HAVING counting > 1 ORDER BY counting DESC") or sqlerr();

if (mysql_num_rows($res) != 0)
{
	begin_table();
	print("<tr align=center><td class=colhead>User name</td><td class=colhead>Email</td><td class=colhead>Registered</td>" . 
	"<td class=colhead>Last Access</td><td class=colhead>Downloaded</td><td class=colhead>Uploaded</td><td class=colhead>Ratio</td>" . 
	"<td class=colhead>IP</td></tr>\n");
	
	$uc = 0;
	
	while($arr = mysql_fetch_assoc($res))
	{
		$uc++;
		$res2 = query("SELECT * FROM users WHERE identhash = '" . $arr["identhash"] . "' ORDER BY id") or sqlerr();
			
		while($arr2 = mysql_fetch_assoc($res2))
		{
			if($arr2["downloaded"] != 0)
				$ratio = number_format($arr2["uploaded"] / $arr2["downloaded"], 3);
			else
				$ratio = "---";
			$ratio = "<font color=" . get_ratio_color($ratio) . ">$ratio</font>";
				
			if($uc%2 == 0)
				$utc = "a08f74";
			else
				$utc = "bbaf9b";
			
			print("<tr bgcolor=\"#$utc\"><td align=left><b><a href='/userdetails.php?id=" . $arr2['id'] . "'>" . $arr2['username'] . "</b></a>" . get_user_icons($arr2) . "</td>" . 
			"<td align=center>" . $arr2['email'] . "</td><td align=center>" . $arr2['added'] . "</td><td align=center>" . $arr2['last_access'] . "</td><td align=center>" . 
			bytesize($arr2['downloaded']) . "</td><td align=center>" . bytesize($arr2['uploaded']) . "</td><td align=center>" . $ratio . "</td><td align=center>" . 
			$arr2['ip'] . "</td></tr>\n");
		}
	}
	
	end_table();
}
else
	print("No duplicate accounts found.");

stdfoot();
?>